package com.xx.chb01.rabbitmq.send;

import com.xx.chb01.rabbitmq.constant.QueueConstants;
import com.xx.chb01.utils.json.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SendTest {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    //发送消息
    public void send(String say) {
        log.info("提交MQ数据: " +  JsonUtils.toJSONString(say));
        this.rabbitTemplate.convertAndSend(QueueConstants.queue_hello, say);
    }


    public void send1() {
        String context = "hi, i am message 1";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("exchange", "topic.message", context);
    }


    public void send2() {

        String context = "hi, i am messages 2";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("exchange", "topic.messages", context);

    }


    public void send3() {

        String context = "这就是rabbitMQ的Direct Exchange。";
        this.rabbitTemplate.convertAndSend("spring-boot-exchange", "point", "增加积分~");
        this.rabbitTemplate.convertAndSend("spring-boot-exchange", "performance", "增加业绩~");
    }
}
